package com.example.wifi_direct.utils

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.example.wifi_direct.R

class LiastAdater (private val context: Context, private val UserList:List<UserData>, private val background:Int): BaseAdapter() {

    override fun getCount(): Int =UserList.size
    override fun getItem(position: Int): Any =UserList[position]
    override fun getItemId(position: Int): Long =position.toLong()
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
        var view=convertView
        val holder: ViewHolder
        if (convertView==null){
            view= LayoutInflater.from(context).inflate(R.layout.user_item,null)
            holder= ViewHolder()
            holder.tv_calorie=view.findViewById<TextView>(R.id.tv_calorie)
            holder.tv_date= view.findViewById<TextView>(R.id.tv_date)
            view.tag=holder
        }else{
            holder= view!!.tag as ViewHolder
        }
//
        var blank= "                     "
//        var blank2="                   "
//        var blank3="                 "
        val User=UserList[position]
//        var length= User.userName!!.length
//        if (length==8)
//            holder.tv_calorie.text=blank+User.passWord.toString()
//        else if (length==9)
//            holder.tv_calorie.text=blank2+User.passWord.toString()
//        else if (length==10)
//            holder.tv_calorie.text=blank3+User.passWord.toString()
        holder.tv_date.text=User.userName+blank+User.passWord+"  "+User.status
        return view
    }

    inner class ViewHolder{
        lateinit var tv_date: TextView
        lateinit var tv_calorie: TextView
    }
}